package ga;

import alg.Evaluation;
import org.jgap.*;
import static alg.Constants.*;
/**
 *
 * @author Dragan Sahpaski
 */
public class DwFitnessFunction extends FitnessFunction {

    Evaluation evaluation;

    public DwFitnessFunction(Evaluation evaluation) {
        this.evaluation = evaluation;
    }

    public double evaluate(IChromosome chromosome) {
        // The root view is always materialized
        chromosome.getGene(evaluation.getDomain().getViewGraph().getRoot().getTableIndex()).setAllele(new Boolean(true));
        evaluation.getDomain().calculateTableVariants(chromosome);
        double value = evaluation.evaluate();
        return MAX_VALUE - value;
    }

    public Evaluation getEvaluation() {
        return evaluation;
    }
}
